<template>
  <el-button
      v-bind="props"
      icon="Close"
      @click="handleCancel"
      v-show="props.show"
  >{{ props.label}}</el-button>
</template>

<script lang="ts" setup>
import eventBus from '@/event/eventBus';
import { getApplication } from "@/api/business/application";
import {
  tableRowSelectChangeKey,resetFormKey,showDialogKey
} from "@/config/app.keys";
import {onMounted, ref, watch,inject,computed} from "vue";
import { formModeKey } from '@/components/form/state.key';
interface Props {
  size?:string
  type?:string
  plain?:boolean
  text?:boolean
  bg?:boolean
  link?:boolean
  round?:boolean
  circle?:boolean
  loading?:boolean
  disabled?:boolean
  autofocus?:boolean
  formData?:object
  id?:string,
  label?: string,
  btId?:string//按钮本身id
  bindDialog?:string//绑定弹窗的id，通常修改时弹出框显示
  show?:boolean,//是否显示
}
const props = withDefaults(defineProps<Props>(), {
  label: '取消',
  id: 0,
  type:"success",
  show:true,
})
const id = ref(0);
const form = ref({});
const single = ref(false)

const formMode = inject(formModeKey)
const cMode = computed<FormFieldMode>(() => {
  if (props.mode) {
    return props.mode
  }
  if (formMode?.value) {
    return formMode.value
  }
  return "edit"
})
watch(() => props.id, (newVal) =>{
  console.log('props.id:'+newVal)
  id.value = newVal
})
onMounted(() => {
  // id.value =props.id
  // eventBus.$on(props.btId+"_"+tableRowSelectChangeKey, (data) => {
  //   if(data.ids.length>0) {
  //     id.value = data.ids[0]
  //     single.value = data.single
  //   }
  // })

})
/** 更新按钮操作 */
function handleCancel() {
  // 只有在 edit 模式下才执行删除操作
  if (cMode.value !== 'edit') {
    return;
  }
  eventBus.$emit(props.bindDialog+"_"+showDialogKey,{title:'',form:{},show:false});
}
</script>

<style scoped>

</style>
